/**
 * 
 */

const HtmlWebpackPlugin = require("html-webpack-plugin");
const { resolve } = require("path");


module.exports = {
    entry:'./src/index.js',
    output:{
        filename:'built.js',
        path:resolve(__dirname,'build'),
    },
    module:{
        rules:[
            {
                test:/\.less$/,
                use:['style-loader','css-loader','less-loader']
            },
            {
                test:/\.css$/,
                use:['style-loader','css-loader']
            },
            {
                test:/\.(webp,jepg,png$)/,
                loader:'url-loader',
                options:{
                    limit:8*1024,
                    name:'[hash:10].[ext]',
                    esModule:false,
                    outputPath:'media'
                }
            },
            {
                test:/\.html$/,
                loader:'html-loader'
            },
            {
                exclude:/.\(js|css|less|html|webp|png|jpeg)$/,
                loader:'file-loader',
                options:{
                    name:'[hash:10].[ext]',
                    outputPath:'js'
                }
            }
        ]
    },
    plugins:[
        new HtmlWebpackPlugin({
            template:'./src/index.html'
        })
    ],
    mode:'production',
    devServer:{
        static : {directory: resolve(__dirname,'build')},
        watchFiles:['./src/index.html'],
        //启动gzip压缩
        compress:true,
        port:3000,
        //自动打开默认浏览器
        open:true
    }
}